<?php
$relPath="../pinc/";
include_once($relPath.'dpinit.php');
include_once($relPath.'dp_main.inc');
// require_once $relPath."theme2.php";

$User->IsLoggedIn()
    or RedirectToLogin();

$projectid  = ArgProjectId()
    or UnauthorizedDeath("no projectid");
$project = new DpProject($projectid);
$project->UserMayManage()
    or UnauthorizedDeath("project authorization");

$langcode = ArgLangCode()
    or $langcode = $project->LanguageCode();
$mode       = Arg("mode");  // flagged, adhoc, suggested, good, bad
$adhoclist  = Arg("adhoclist");
$btnadhoc   = IsArg("btnadhoc");

switch($mode) {
    default:
    case "flagged":
        $awords = $project->FlagWordsByCountAlpha($langcode);
        break;


    case "suggested":
        $awords = $project->SuggestedWordsByCountAlpha($langcode);
        break;

    case "adhoc":
        $awords = $project->AdHocWordCountArray(
                                    $langcode, $adhoclist);
        break;

    case "good":
        $awords = $project->GoodWordsByCountAlpha($langcode);
        break;

    case "bad":
        $awords = $project->BadWordsByCountAlpha($langcode);
        $tpl = _("Bad Words (%d) will be flagged.");
        break;
}

$js = "
    var AJAX_URL = '{$ajax_url}';
    var SITE_URL = '{$site_url}';
";

DpHeader("Word Context", array(
                    "jstext"  => $js, 
                    "onload"  => "eContextInit()",
                    "jsfile"  => "dp_edit.js",
                    "cssfile" => "context.css"));

$selected = " selected='selected'";

echo "
<div id='container'>
<form id='formcontext' name='formcontext' method='POST'>
<input type='hidden' name='projectid'  value='{$projectid}'>
<input type='hidden' name='activeword' value=''>
<div id='left-column'>
  <div id='command-section'>
    <div>"
      .link_to_project_words($projectid, _("Return to project words"))
    ."</div>
    <div>
      ".LanguagePicker("langcode", $langcode, "", 
                            "document.formcontext.submit()")."
    </div>
    <div>
      ".WordlistPicker("mode", $mode, "", 
                            "document.formcontext.submit()")."
    </div>
    <div id='buttonbox'>
      <input type='button' name='btngood'     value='Good'>
      <input type='button' name='btnbad'      value='Bad'>
      <input type='button' name='btndelete'   value='Delete'>
    </div>
  </div>   <!-- command-section -->
  <div>\n";
  if($mode == "adhoc") {
    echo "
    <div id='adhoc'>
        <div id='adhocctl'>
            "._("Enter words")."
            <input type='submit' name='btnadhoc' 
                id='btnadhoc' value='"._("Submit")."'>
        </div>
        <textarea name='adhoclist' id='adhoclist'>"
        .$adhoclist."</textarea>
    </div>\n";
  }

  echo "
  <select name='tblcontext' id='tblcontext'
                      size='30'
                      onchange='eTblContextChange(event)'>\n";
  foreach($awords as $aword) {
      $w = $aword[0];
      if($w != "") {
          $c = $aword[1];
          echo "
        <option id=\"w_{$w}\" value=\"w_{$w}\" 
                          $selected>$w ($c)</option>\n";
          $selected = "";
      }
  }
  echo "
  </select>
  </div>
</div>    <!-- left-column -->
<div id='div_context_box'>
  <div id='div_context_list'>
  </div> <!--  div_context_list   -->
  <div id='div_context_image'>
    <img id='imgcontext' src='' alt='context image'
                                    onload='eContextImgLoad()'>
  </div> <!--  div_context_image   -->
</div> <!--  div_context_box   -->
</form>
</div>
</body></html>";
exit;

// vim: sw=4 ts=4 expandtab
?>
